package com.hula.onion.book.server.spider.platforms.yirendai;

import com.hula.onion.book.server.common.CommonResponse;
import com.hula.onion.book.server.common.SpiderCommon;
import com.hula.onion.book.server.config.ResponseStatusEnum;
import com.hula.onion.book.server.spider.platforms.tuandai.TuanDaiSpiderHelper;
import com.hula.onion.book.server.utils.HttpUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * Description:宜人贷spider
 * Create Date:2018/1/17 19:33
 *
 * @author liangbing
 * @version 1.0
 */
@Component("yiRenDaiSpider")
public class YiRenDaiSpider extends SpiderCommon {

    /**
     * 登录URL
     */
    private static final String LOGIN_URL = "https://login.yirendai.com/auth/loginsubmit";
    /**
     * 获取账户信息URL
     */
    public static final String GET_ACCOUNT_INFO_URL = "https://www.yirendai.com/lender/cashflow/1";

    @Autowired
    private YiRenDaiSpiderHelper yiRenDaiSpiderHelper;

    /**
     * 执行爬取操作
     * 1.获取 RSA key
     * 2.组装模拟登陆参数，模拟登陆
     * 3.爬取用户详细信息
     */
    @Override
    public CommonResponse execute() {

        Map<String, Object> params =
                yiRenDaiSpiderHelper.installRequestParams(loginForm);

        //1 登陆并且重定向到账户详情页
        String html = HttpUtils.post(LOGIN_URL, params,null);

        logger.info(html);
        //解析html
        return yiRenDaiSpiderHelper.parseHtml(html);
    }
}
